package fx;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

/**
 * Created by thormentor on 19-05-2014.
 */
public class SceneBuilder {
    private final Object o;
    private final Stage stage;
    private boolean fullscreen = false;

    public SceneBuilder(Object o, Stage stage) {
        this.o = o;
        this.stage = stage;
    }

    public SceneBuilder setFullscreen() {
        fullscreen = true;
        return this;
    }

    public void build() {
        Parent parent;
        try {
            parent = FXMLLoader.<Parent>load(o.getClass().getResource(o.getClass().getSimpleName().replace("Application", "") + ".fxml"), FX.getBundle(o));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Scene scene = new Scene(parent);

        stage.setScene(scene);

        if (fullscreen)
            stage.setFullScreen(true);

        stage.show();
    }
}
